package cn.edu.sdjzu.xg.eagle.mapper;

import cn.edu.sdjzu.xg.eagle.entities.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeacherMapper {

    @Select("SELECT TeacherID, Name, Gender, College, Office, ContactInfo, PhotoID, Password FROM teacher WHERE TeacherID = #{teacherId}")
    @Results({
            @Result(property = "teacherId", column = "TeacherID"),
            @Result(property = "name", column = "Name"),
            @Result(property = "gender", column = "Gender"),
            @Result(property = "college", column = "College"),
            @Result(property = "office", column = "Office"),
            @Result(property = "contactInfo", column = "ContactInfo"),
            @Result(property = "photoId", column = "PhotoID"),
            @Result(property = "password", column = "Password")
    })
    Teacher getTeacher(Integer teacherId);

    @Select("SELECT TeacherID, Name, Gender, College, Office, ContactInfo, PhotoID, Password FROM teacher")
    @Results({
            @Result(property = "teacherId", column = "TeacherID"),
            @Result(property = "name", column = "Name"),
            @Result(property = "gender", column = "Gender"),
            @Result(property = "college", column = "College"),
            @Result(property = "office", column = "Office"),
            @Result(property = "contactInfo", column = "ContactInfo"),
            @Result(property = "photoId", column = "PhotoID"),
            @Result(property = "password", column = "Password")
    })
    List<Teacher> getTeachers();

    @Insert("INSERT INTO Teacher (Name, Gender, College, Office, ContactInfo, PhotoID, Password) VALUES (#{name}, #{gender}, #{college}, #{office}, #{contactInfo}, #{photoId}, #{password})")
    @Options(useGeneratedKeys = true, keyProperty = "teacherId")
    boolean addTeacher(Teacher teacher);

    @Update("UPDATE Teacher SET Name = #{name}, Gender = #{gender}, College = #{college}, Office = #{office}, ContactInfo = #{contactInfo}, PhotoID = #{photoId}, Password = #{password} WHERE TeacherID = #{teacherId}")
    boolean updateTeacher(Teacher teacher);

    @Delete("DELETE FROM Teacher WHERE TeacherID = #{teacherId}")
    boolean deleteTeacher(Integer teacherId);
}